<template>
	<view>
		<!-- 顶部tab-bar -->
		<swiper-tab-head :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap"/>
		<!-- 轮播视图 -->
		<view class="uni-tab-bar">
			<swiper class="swiper-box" 
			:style="{'height':swiperheight + 'px'}"
			:current="tabIndex"
			@change="tabChange">
				<swiper-item v-for="(items, index) in newsList" :key="index">
					<scroll-view scroll-y class="list" @scrolltolower="loadmore(index)">
						<template v-if="items.list.length > 0">
							<!-- 话题列表 -->
							<block v-for="(item, index1) in items.list" :key="index1">
								<topic-list :item="item" :index="index1"></topic-list>
							</block>
							<!-- 上拉加载更多 -->
							<load-more :loadtext="items.loadtext"></load-more>
						</template>
						<template v-else>
							<!-- 无内容默认 -->
							<no-thing></no-thing>
						</template>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import swiperTabHead from "../../components/index/swiper-tab-head.vue";
	import loadMore from "../../components/common/load-more.vue";
	import noThing from "../../components/common/no-thing.vue";
	import topicList from '../../components/news/topic-list.vue';
	
	export default {
		components:{
			swiperTabHead,
			loadMore,
			noThing,
			topicList
		},
		data() {
			return {
				tabIndex:0,
				swiperheight: 500,
				tabBars:[
					{
					    name: '关注',
					    id: 'guanzhu'
					}, {
					    name: '推荐',
					    id: 'tuijian'
					}, {
					    name: '体育',
					    id: 'tiyu'
					}, {
					    name: '热点',
					    id: 'redian'
					}, {
						name: '财经',
						id: 'caijing'
					}, {
						name: '娱乐',
						id: 'yule'
					}
				],
				newsList:[
					{
						loadtext: '上拉加载更多',
						list: [
							{
								cover: '../../static/images/cbd.jpg',
								title: '今日份--吃',
								desc: '吃的过瘾',
								totalnum: 245,
								todaynum: 23445
							},
							{
								cover: '../../static/images/cbd.jpg',
								title: '今日份--喝',
								desc: '喝的痛快',
								totalnum: 245,
								todaynum: 23445
							},
							{
								cover: '../../static/images/cbd.jpg',
								title: '今日份--玩',
								desc: '玩的舒服',
								totalnum: 245,
								todaynum: 23445
							},
							{
								cover: '../../static/images/cbd.jpg',
								title: '今日份--乐',
								desc: '快乐就是这么简单',
								totalnum: 245,
								todaynum: 23445
							}
						]
					},
					{
						loadtext: '上拉加载更多',
						list: []
							
					},
					{
						loadtext: '上拉加载更多',
						list: []
					},
					{
						loadtext: '上拉加载更多',
						list: []
					},
					{
						loadtext: '上拉加载更多',
						list: []
					},
					{
						loadtext: '上拉加载更多',
						list: []
					}
				]
			}
		},
		onLoad() {
			/* 获取屏幕的可用高度 */
			uni.getSystemInfo({
				success: (res) => {
					let height = res.windowHeight - uni.upx2px(100);
					console.log(height);
					this.swiperheight = height;
				}
			});
		},
		methods: {
			/*  */
			tabtap(index){
				this.tabIndex = index
			},
			/* 导航变化 */
			tabChange(e){
				this.tabIndex = e.detail.current;
			},
			/* 上拉加载更多 */
			loadmore(index){
				if(this.newsList[index].loadtext !== '上拉加载更多'){
					return;
				}
				// 修改加载状态
				this.newsList[index].loadtext = '加载中···';
				// 获取数据
				setTimeout(() => {
					var obj = {
						
					};
					// 获取完成
					this.newsList[index].loadtext = '上拉加载更多';
				}, 1000)
		
				
				// this.newsList[index].loadtext = '没有更多数据了';
			}
		}
	}
</script>

<style>

</style>
